import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/login/UserLogin.vue')
    },
    {
      path: '/register',
      component: () => import('@/views/login/UserRegister.vue')
    },
    {
      path: '/',
      component: () => import('@/views/layout/layout.vue'),
      redirect: 'game/list',
      children: [
        {
          path: 'myorder',
          component: () => import('@/views/user/order/MyOrder.vue')
        },
        {
          path: 'unpayorder',
          component: () => import('@/views/user/order/UnPayOrder.vue')
        },
        {
          path: 'game/list',
          component: () => import('@/views/user/GameList.vue')
        },
        {
          path: 'shoppingcart',
          component: () => import('@/views/user/ShoppingCart.vue')
        },
        {
          path: 'gamedetail/:id',
          name: 'GameDetail',
          component: () => import('@/views/user/game/GameDetail.vue')
        },
        {
          path: 'user',
          component: () => import('@/views/user/UserLayout.vue'),
          redirect: 'user/info',
          children: [
            {
              path: 'info',
              component: () => import('@/views/user/info/UserInfo.vue')
            },
            {
              path: 'recharge',
              component: () => import('@/views/user/info/ReCharge.vue')
            },
            {
              path: 'password',
              component: () => import('@/views/user/info/RePassword.vue')
            },
            {
              path: 'image',
              component: () => import('@/views/user/info/UserImage.vue')
            }
          ]
        },
        {
          path: 'boss',
          component: () => import('@/views/boss/BossLayout.vue'),
          redirect: 'boss/publish',
          children: [
            {
              path: 'publish',
              component: () => import('@/components/boss/PublishGame.vue')
            },
            {
              path: 'order',
              component: () => import('@/components/boss/OrderManage.vue')
            },
            {
              path: 'count',
              component: () => import('@/components/boss/CountOrders.vue')
            },
            {
              path: 'upload',
              component: () => import('@/components/boss/UpLoad.vue')
            },
            {
              path: 'published',
              component: () => import('@/components/boss/DonePublish.vue')
            },
            {
              path: 'sort',
              component: () => import('@/components/boss/GameSort.vue')
            },
            {
              path: 'library',
              component: () => import('@/components/user/GameLibrary.vue')
            },
            {
              path: 'auditGame',
              component: () => import('@/views/admin/AuditGame.vue')
            },
            {
              path: 'manageUser',
              component: () => import('@/views/admin/ManageUser.vue')
            }
          ]
        }
      ]
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0, left: 0 }
    }
  }
})

export default router
